import '../apis/resquest/http.dart';
import '../model/bean/facility_ability_fean.dart';
import '../model/bean/lift_info_bean.dart';
import '../model/bean/lift_management_list_bean.dart';
import '../model/bean/lift_token.dart';
import '../model/bean/manage_elevator_num_bean.dart';

class Elevator {
  /// 查询管理电梯数（首页使用）
  /// * [data] Map|请求参数|必填
  static queryManageElevatorNum() async {
    const url = '/elevator-maintenance-app/elevator/numberOfElevators';
    try {
      HttpResponse _r = await Http.getInstance().get(url);
      return ManageElevatorNumBean.fromJson(_r.data);
    } catch (e) {}
  }

  /// 查询维保人员管理电梯（电梯管理使用）
  /// * [data] Map|请求参数|必填
  /// * [type] int|请求数据类型|必填（用于区分“全部”|“已告警”的数据）
  static queryMaintainer(Map<String, dynamic> data, int type) async {
    const url = '/elevator-maintenance-app/elevator/getByMaintainer';
    try {
      HttpResponse _r = await Http.getInstance().get(url, params: data);
      if (type == 0) {
        return LiftManagementListBean.fromJson(_r.data);
      } else {
        // 因“已告警”与“全部”数据结构不一致，此处将“已告警”数据进行结构转化
        Map<String, dynamic> _temporary = {
          "list": _r.data,
          "total": _r.data.length
        };
        return LiftManagementListBean.fromJson(_temporary);
      }

      //return LiftManagementListBean.fromJson(_temporary);
    } catch (e) {}
  }

  /// 查询电梯信息
  /// * [data] Map|请求参数|必填
  static queryLiftInfo(Map<String, dynamic> data) async {
    const url = '/elevator-maintenance-app/elevator/getById';
    try {
      HttpResponse _r = await Http.getInstance().get(url, params: data);
      return LiftInfoBean.fromJson(_r.data);
    } catch (e) {}
  }

  /// 查询电梯凭证
  /// * [data] Map|请求参数|必填
  static queryLiftToken(Map<String, dynamic> data) async {
    const url = '/elevator-maintenance-app/elevator/accessToken';
    try {
      HttpResponse _r = await Http.getInstance().get(url, params: data);
      return LiftToken.fromJson(_r.data);
    } catch (e) {}
  }

  /// 查询监测设备能力
  /// * [data] Map|请求参数|必填
  static queryFacilityAbility(Map<String, dynamic> data) async {
    const url = '/elevator-maintenance-app/monitor/ability';
    try {
      HttpResponse _r = await Http.getInstance().get(url, params: data);
      return FacilityAbilityBean.fromJson(_r.data);
    } catch (e) {}
  }
}
